package com.bw.permission.controller;


import com.bw.permission.common.AjaxResult;
import com.bw.permission.entity.Area;
import com.bw.permission.entity.Menu;
import com.bw.permission.service.IMenuService;
import com.bw.permission.utils.JwtUtils;
import com.bw.permission.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanggm
 * @since 2021-08-18
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private IMenuService iMenuService;

    @Autowired
    private JwtUtils jwtUtils;

    /**
     * 查询所有菜单（树结构，只查询2级）
     * @return
     */
    @GetMapping("getTreeData")
    public AjaxResult getTreeData() {
        Integer curUserId = jwtUtils.getCurUserId();
        //查询1级菜单list
        List<Menu> menuList = iMenuService.getMenuTreeByUserId(curUserId);
       /* //查询市
        //list、set、map 否forEach
        menuList.forEach(menu->{
            //根据1级菜单Id，查询子菜单
            List<Menu> shiList = iMenuService.getListByParentId(menu.getId());
            menu.setSubMenuList(shiList);

        });*/
        return AjaxResult.ok(menuList);
    }



}
